let back = document.querySelector('.sugTop')
let tops = document.querySelector('.tops')
let rankrigs = document.querySelector('.rankrig')
let rankyps = document.querySelectorAll('.rankyp')
let wbsa = document.querySelectorAll('.wbs')
let wbcolors = document.querySelectorAll('.wbcolor')
   let rankypsa = document.querySelector('.rankyps')  // 消费榜
let pages = document.querySelectorAll('.page')

let ranklists = document.querySelectorAll('.ranklist')

function tz() {
    pages.forEach(function(params) {
        params.classList.remove('color')
        params.addEventListener('click',function(){
        params.classList.add('color')
    })   
    })
  
   
}


   window.addEventListener('scroll', function () {
    let distance = this.window.scrollY
    if (distance > 170) {
        back.style.display = 'block'
        tops.style.display = 'block'

    } else {
        back.style.display = 'none'
        tops.style.display = 'none'
    }
})
function backs(params) {
    window.scrollTo({
        top: 0,
        behavior: 'smooth'
    })

}
let indexs = document.querySelector('.bodys')
let rankBodys = document.querySelector('.rankBody')
let data = { key: 'value' }
function fench(a,b,n=1) {
   return  fetch(`https://www.qimao.com/qimaoapi/api/classify/book-list?channel=a&category1=${a}&category2=${b}&words=a&update_time=a&is_vip=a&is_over=a&order=words_num&page=${n}`, {
        // method: 'GET',
        // headers: {
        //     'Content-Type': 'application/json'
        // },
        // body: JSON.stringify(data)
    })
       .then(response =>response.json())
        .then(result => {
            return result
            
        })
        .catch(error => {
            console.log(error);
        })
        
}


function rank() {
     wbcolors.forEach(function(params) {
      params.classList.remove('wbsColor')
  })
  event.target.classList.add('wbsColor')
    indexs.style.display = 'none'
    rankBodys.style.display = 'flex'
     rankrigs.classList.remove('hide')
     rankyps.forEach(function(params) {
     params.classList.add('hide')
   })
   fench()
}

function index(params) {
      wbcolors.forEach(function(params) {
      params.classList.remove('wbsColor')
  })
  event.target.classList.add('wbsColor')
    indexs.style.display = 'block'
    rankBodys.style.display = 'none'
}


function yp(a1) {
   
      rankypsa.style.display = 'none'
 wbsa.forEach(function(params) {
    params.classList.remove('wbsColor')
 })
 event.target.classList.add('wbsColor')
  rankrigs.classList.add('hide')
   let rqs = document.querySelectorAll('.rq')
      rqs.forEach(function (params) {
        params.innerHTML = ''
         
     })

   if (event.target.id == 1) {
   tz()
       ranklists[0].style.display = 'none'
 setTimeout(() => {
     ranklists[0].style.display = 'block'
 }, 1000);
      rankyps.forEach(function(params) {
        params.classList.add('hide')
    })
    
       let n = a1
          rankyps[0].classList.remove('hide')
        fench('a','a',n).then(result=>{
           
            let books = result.data.book_list
       books.forEach(function(item,index) {
        
          rqs[0].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>
            

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })
    
        
       
   }else if(event.target.id == 2){
    tz()
     ranklists[1].style.display = 'none'
 setTimeout(() => {
     ranklists[1].style.display = 'block'
 }, 1000);
    rankyps.forEach(function(params) {
        params.classList.add('hide')
    })

          rankyps[1].classList.remove('hide')
        fench(1,8,a1).then(result=>{
            
            let books = result.data.book_list
       books.forEach(function(item,index) {
          rqs[1].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })


   }else if(event.target.id == 3){
     tz()
         ranklists[2].style.display = 'none'
 setTimeout(() => {
     ranklists[2].style.display = 'block'
 }, 1000);
      rankyps.forEach(function(params) {
        params.classList.add('hide')
    })
      rankyps[2].classList.remove('hide')
       fench('a',11,a1).then(result=>{
        console.log(result.data);
        
            let books = result.data.book_list
       books.forEach(function(item,index) {
          rqs[2].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })
   }else if(event.target.id == 4){
    tz()
         ranklists[3].style.display = 'none'
 setTimeout(() => {
     ranklists[3].style.display = 'block'
 }, 1000);
      rankyps.forEach(function(params) {
        params.classList.add('hide')
        
    })
      rankyps[3].classList.remove('hide')
       fench('a',12,a1).then(result=>{
       
            let books =  result.data.book_list
       books.forEach(function(item,index) {
          rqs[3].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })
   }else if(event.target.id == 5){
    tz()
         ranklists[4].style.display = 'none'
 setTimeout(() => {
     ranklists[4].style.display = 'block'
 }, 1000);
      rankyps.forEach(function(params) {
        params.classList.add('hide')
    })
      rankyps[4].classList.remove('hide')
       fench('a',13,a1).then(result=>{
       
            let books =  result.data.book_list
       books.forEach(function(item,index) {
          rqs[4].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })
   }else if(event.target.id == 6){
    tz()
         ranklists[5].style.display = 'none'
 setTimeout(() => {
     ranklists[5].style.display = 'block'
 }, 1000);
      rankyps.forEach(function(params) {
        params.classList.add('hide')
    })
      rankyps[5].classList.remove('hide')
       fench('a',16,a1).then(result=>{
       
            let books =  result.data.book_list
       books.forEach(function(item,index) {
          rqs[5].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })
   }else if(event.target.id == 7){
    tz()
         ranklists[6].style.display = 'none'
 setTimeout(() => {
     ranklists[6].style.display = 'block'
 }, 1000);
      rankyps.forEach(function(params) {
        params.classList.add('hide')
    })
      rankyps[6].classList.remove('hide')
          fench('a',25,a1).then(result=>{
       
            let books =  result.data.book_list
       books.forEach(function(item,index) {
          rqs[6].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })
   }else if(event.target.id == 8){
         ranklists[7].style.display = 'none'
 setTimeout(() => {
     ranklists[7].style.display = 'block'
 }, 1000);
      rankyps.forEach(function(params) {
        params.classList.add('hide')
    })
      rankyps[7].classList.remove('hide')
          fench('a',22,a1).then(result=>{
       
            let books =  result.data.book_list
       books.forEach(function(item,index) {
          rqs[7].innerHTML += `
                 <li>
                  <img src="${item.image_link}" alt="">
                    <div class="rqleft">
                        <p class="rqtit">${item.author}</p>
                        <p class="rqtype">${item.category2_name}</p>
                        <p class="rqwbs">${item.intro}</p>
                       <div class="rqcamp">
                         <p>${item.update_time}</p>
                         <p>${item.update_time_txt}</p>
                       </div>
                    </div>

                    <div class="rqrig">
                        <div class="rqtits">${index+1>3?index+1:''}
                        </div>
                        <div class="rqbut">立即阅读</div>
                        <div class="rqjoin">加入书架</div>
                    </div>
                </li>

          `
          
       })

        })
        .catch(error =>{
            console.log(error);
            
        })
   }
  
}


function xfs(params) {
  wbsa.forEach(function(params) {
    params.classList.remove('wbsColor')
 })
 event.target.classList.add('wbsColor')
  rankrigs.classList.add('hide')
   let rqs = document.querySelectorAll('.rq')
      rqs.forEach(function (params) {
        params.innerHTML = ''
         
     })
       rankyps.forEach(function(params) {
        params.classList.add('hide')
    })
    rankypsa.style.display = 'block'
           
}
nd=()=>{
    window.location.href='naodongindex.html'
}
rank1=()=>{
    window.location.href='bookstock.html'
}
rank2=()=>{
    window.location.href='征文专区/needArtical.html'
}
rank3=()=>{
    window.location.href='index.html'
}
rank4=()=>{
    window.location.href='漫画/MH.html'
}
rank5=()=>{
    window.location.href='login.html'
}
rank6=()=>{
    window.location.href='books.html'
}
to=()=>{
    console.log(9999)
     const inputElement = document.querySelector('.tpsearch');
    const searchText = inputElement.value.trim();
        console.log(searchText);
        inputElement.value = '';
        window.location.href = 'shearh.html?searchText=' + searchText;
}
diji=()=>{
    window.location.href='naodongxingqiu_author.html'
}
ju=()=>{
    console.log(9999)
    window.location.href='detail.html'
}
    //  onclick="ju()"